import { history } from '@@/exports';
import type { MenuProps } from 'antd';
import { Dropdown, Modal } from 'antd';

const { confirm } = Modal;

const RightButton: React.FC<{
  children: React.ReactNode;
  articleId: number;
  clickDel: (articleId: number) => void;
}> = ({ articleId, children, clickDel }) => {
  const items: MenuProps['items'] = [
    {
      label: <text onClick={() => operate('edit')}>编辑</text>,
      key: '1',
    },
    {
      label: <text onClick={() => operate('delete')}>删除</text>,
      key: '2',
    },
  ];

  function operate(type: string) {
    switch (type) {
      case 'edit':
        history.push(`/creationCenter/edit/${articleId}`);
        break;
      case 'delete':
        clickDel(articleId);
        break;
    }
  }

  return (
    <Dropdown menu={{ items }} trigger={['contextMenu']}>
      {children}
    </Dropdown>
  );
};

export default RightButton;
